package net.vanchu.mortgagecalculator.common.commonView.component;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dtspread.apps.houseloan.R;


/**
 * Created by Granton on 2016/12/16.
 */
public class SelectingOptionsLayout extends RelativeLayout {

    private static final String TAG = SelectingOptionsLayout.class.getSimpleName();

    private TextView leftTextView;

    private TextView rightTextView;

    public SelectingOptionsLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs, 0);
    }

    public SelectingOptionsLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        View parentView = LayoutInflater.from(context).inflate(R.layout.layout_option_to_select, this, true);
        leftTextView = (TextView) parentView.findViewById(R.id.left_text);
        rightTextView = (TextView) parentView.findViewById(R.id.right_text);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OptionsLayout, 0, defStyleAttr);
        leftTextView.setText(a.getString(R.styleable.OptionsLayout_left_text));
        rightTextView.setText(a.getString(R.styleable.OptionsLayout_right_text));
        a.recycle();
    }

    public void setLeftTextViewText(int resId) {
        setLeftTextViewText(getContext().getString(resId));
    }

    public void setLeftTextViewText(String text) {
        this.leftTextView.setText(text);
    }

    public void setRightTextViewFontColor(int color) {
        this.rightTextView.setTextColor(getResources().getColor(color));
    }

    public void setRightTextViewText(int resId) {
        setRightTextViewText(getContext().getString(resId));
    }

    public void setRightTextViewText(String text) {
        this.rightTextView.setText(text);
    }

    public void setRightTextViewClickListener(OnClickListener onClickListener) {
        this.rightTextView.setOnClickListener(onClickListener);
    }

}